//
//  YSSpreadSheetViewProtocol.swift
//  YSSpreadSheetView
//
//  Created by 万孟超 on 2023/5/5.
//

import UIKit

@MainActor @objc public protocol YSSpreadSheetViewDataSource: NSObjectProtocol {
    
    /// 表格列数，不受`isShowItemTitle`影响
    /// - Parameter spreadSheetView: 表格
    /// - Returns: 列数
    func numberOfItems(in spreadSheetView: YSSpreadSheetView) -> Int
    
    /// 表格行数，不受`isShowSectionTitle`影响
    /// - Parameter spreadSheetView: 表格
    /// - Returns: 行数
    func numberOfSections(in spreadSheetView: YSSpreadSheetView) -> Int
    
    /// `isShowSectionTitle`为`true`时标题
    /// - Parameters:
    ///   - spreadSheetView: 表格
    ///   - section: 第几行
    /// - Returns: 标题Cell
    @objc optional func spreadSheetView(_ spreadSheetView: YSSpreadSheetView, titleViewForSectionAt section: Int) -> YSSpreadSheetSubView?
    
    /// `isShowItemTitle`为`true`时标题
    /// - Parameters:
    ///   - spreadSheetView: 表格
    ///   - item: 第几列
    /// - Returns: 标题Cell
    @objc optional func spreadSheetView(_ spreadSheetView: YSSpreadSheetView, titleViewForItemAt item: Int) -> YSSpreadSheetSubView?
    
    /// `section`的高度
    /// - Parameters:
    ///   - spreadSheetView: 表格
    ///   - section: 行
    /// - Returns: 高度
    @objc optional func spreadSheetView(_ spreadSheetView: YSSpreadSheetView, heightForCellAt section: Int) -> CGFloat
    
    /// `item`的宽度
    /// - Parameters:
    ///   - spreadSheetView: 表格
    ///   - item: 列
    /// - Returns: 宽度
    @objc optional func spreadSheetView(_ spreadSheetView: YSSpreadSheetView, widthForCellAt item: Int) -> CGFloat
    
    /// Cell代理 不受`isShowItemTitle，isShowSectionTitle`影响
    /// - Parameters:
    ///   - spreadSheetView: 表格
    ///   - indexPath: 几行几列
    /// - Returns: Cell
    func spreadSheetView(_ spreadSheetView: YSSpreadSheetView, cellAt indexPath: IndexPath) -> YSSpreadSheetSubView?
    
    /// `section`行可高亮的个数
    /// - Parameters:
    ///   - spreadSheetView: 表格
    ///   - section: 第几行
    /// - Returns: 可高亮个数
    @objc optional func spreadSheetView(_ spreadSheetView: YSSpreadSheetView, sectionHighLightCountIn section: Int) -> Int
    
    /// `item`中可高亮的个数
    /// - Parameters:
    ///   - spreadSheetView: 表格
    ///   - item: 第几列
    /// - Returns: 可高亮个数
    @objc optional func spreadSheetView(_ spreadSheetView: YSSpreadSheetView, itemHighLightCountIn item: Int) -> Int
}

@MainActor @objc public protocol YSSpreadSheetViewDelegate: UIScrollViewDelegate {
    
    /// Cell是否可以高亮
    /// - Parameters:
    ///   - spreadSheetViewCell: Cell
    ///   - indexPath: 几行几列
    /// - Returns: 是否可以高亮
    @objc optional func spreadSheetView(_ spreadSheetViewCell: YSSpreadSheetSubView, shouldHighlightAt indexPath: IndexPath) -> Bool
    
    /// Cell已经高亮
    /// - Parameters:
    ///   - spreadSheetViewCell: Cell
    ///   - indexPath: 几行几列
    @objc optional func spreadSheetView(_ spreadSheetViewCell: YSSpreadSheetSubView, didHighlightAt indexPath: IndexPath)
    
    /// Cell是否可以取消高亮
    /// - Parameters:
    ///   - spreadSheetViewCell: Cell
    ///   - indexPath: 几行几列
    /// - Returns: 是否可以取消高亮
    @objc optional func spreadSheetView(_ spreadSheetViewCell: YSSpreadSheetSubView, shouldUnHighlightAt indexPath: IndexPath) -> Bool
    
    /// Cell已经取消高亮
    /// - Parameters:
    ///   - spreadSheetViewCell: Cell
    ///   - indexPath: 几行几列
    @objc optional func spreadSheetView(_ spreadSheetViewCell: YSSpreadSheetSubView, didUnHighlightAt indexPath: IndexPath)
    
    /// Cell是否可以选中
    /// - Parameters:
    ///   - spreadSheetViewCell: Cell
    ///   - indexPath: 几行几列
    /// - Returns: 是否可以选中
    @objc optional func spreadSheetView(_ spreadSheetViewCell: YSSpreadSheetSubView, shouldSelectItemAt indexPath: IndexPath) -> Bool
    
    /// 是否可以取消选中
    /// - Parameters:
    ///   - spreadSheetViewCell: Cell
    ///   - indexPath: 几行几列
    /// - Returns: 是否可以取消高亮
    @objc optional func spreadSheetView(_ spreadSheetViewCell: YSSpreadSheetSubView, shouldDeselectItemAt indexPath: IndexPath) -> Bool
    
    /// 选中Cell
    /// - Parameters:
    ///   - spreadSheetViewCell: Cell
    ///   - indexPath: 几行几列
    @objc optional func spreadSheetView(_ spreadSheetViewCell: YSSpreadSheetSubView, didSelectItemAt indexPath: IndexPath)
    
    /// 取消选中Cell
    /// - Parameters:
    ///   - spreadSheetViewCell: Cell
    ///   - indexPath: 几行几列
    @objc optional func spreadSheetView(_ spreadSheetViewCell: YSSpreadSheetSubView, deselectItemAt indexPath: IndexPath)
}
